package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.pojo.Events;
import com.example.demo.service.Eservice;
import org.springframework.stereotype.Service;
import com.example.demo.mapper.EventsMapper;
import java.util.List;

@Service
public class EserviceImpl extends ServiceImpl<EventsMapper, Events> implements Eservice {


    @Override
    public Page<Events> page(Integer current, Integer size, String name) {
        if (current == null || current <= 0) current = 1;
        if (size == null || size <= 0) size = 10;
        LambdaQueryWrapper<Events> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null && !name.trim().isEmpty()) {
            queryWrapper.like(Events::getName, name.trim());
        }
        return super.page(new Page<>(current, size), queryWrapper);
    }
    @Override
    public boolean saveOrUpdateBymemberId(Events event) {
        if (event == null) {
            throw new IllegalArgumentException("事件对象不能为空");
        }
        if (event.getId() != null && event.getId() > 0) {
            return updateById(event);
        } else {
            return save(event);
        }
    }
    @Override
    public boolean deleteBatchIds(List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return false;
        }

        return removeByIds(ids);
    }
}